import '../libs/weapp-adapter'
import * as THREE from '../libs/three'

class Main {
    constructor() {

    }

    init() {
        var renderer = new THREE.WebGLRenderer({
            canvas
        })

        var scene = new THREE.Scene()

        var camera = new THREE.OrthographicCamera(
            -200,
            200,
            200,
            -200,
            -1000,
            1000
        )
        console.log(canvas.width, canvas.height)
        renderer.setClearColor(new THREE.Color(0x000000), 1.0)
        renderer.setSize(
            canvas.width,
            canvas.height
        )

        var triangleShape = new THREE.Shape()
        triangleShape.moveTo(0, 100)
        triangleShape.lineTo(-100, -100)
        triangleShape.lineTo(100, -100)
        triangleShape.lineTo(0, 100)

        var geomtry = new THREE.ShapeGeometry(triangleShape)
        var material = new THREE.MeshBasicMaterial({
            color: 0xff00ff,
            side: THREE.DoubleSide
        })
        var mesh = new THREE.Mesh(geomtry, material)

        scene.add(mesh)

        var currentAngle = 0
        var lastTimeStamp = Date.now()
        var animate = function () {
            var now = Date.now()
            var duration = now - lastTimeStamp
            lastTimeStamp = now
            currentAngle += duration / 1000 * Math.PI
        }
        var i = 0
        var render = function () {
            animate()
            mesh.rotation.set(0, currentAngle, 0)
            renderer.render(scene, camera)
            requestAnimationFrame(render)
        }
        render()
    }
}

export default new Main()